import request from '@/utils/request'
import { AxiosResponse } from 'axios'

export const getQueryCourses = (data:any):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/front/course/getQueryCourses',
    data
  })
}

export const changeState = (data:any):Promise<AxiosResponse> => {
  return request({
    method: 'GET',
    url: '/boss/course/changeState',
    params: data
  })
}

export const saveOrUpdateCourse = (data:any):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/boss/course/saveOrUpdateCourse',
    data
  })
}

export const upload = (
  data:any,
  onUploadProgress?:(progressEvent:ProgressEvent)=>void
):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/boss/course/upload',
    data,
    onUploadProgress
    // (e) {
    //   console.log(Math.floor(e.loaded / e.total * 100))
    // }
  })
}

export const getCourseById = (courseId:string|number):Promise<AxiosResponse> => {
  return request({
    method: 'GET',
    url: '/boss/course/getCourseById',
    params: {
      courseId
    }
  })
}

export const getSectionAndLesson = (courseId:string|number):Promise<AxiosResponse> => {
  return request({
    method: 'GET',
    url: '/boss/course/section/getSectionAndLesson',
    params: {
      courseId
    }
  })
}

export const saveOrUpdateSection = (data:any):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/boss/course/section/saveOrUpdateSection',
    data
  })
}

export const saveOrUpdateLesson = (data:any):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/boss/course/lesson/saveOrUpdate',
    data
  })
}
